#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+5;
typedef long long ll;
vector<int> a[N];
int b[N], k[N], c, n;
int whenin[N<<1], wicnt = 0;
ll calc(int x){
    ll ans = 0;
    wicnt = 0;
    for(int i=1;i<=n;i++){
        if(k[i] == 1){
            ans += 1ll*x*c;
            whenin[++wicnt] = a[i][0];
            continue;
        }
        whenin[++wicnt] = a[i][0];
        for(int j=0;j<k[i]-1;j++){
            if(a[i][j+1] > a[i][j] + x - 1){
                whenin[++wicnt] = a[i][j+1];
                ans += 1ll*x*c;
            }else{
                ans += 1ll*(a[i][j+1]-a[i][j])*c;
            }
        }
        ans += 1ll*x*c;
    }
    sort(whenin+1, whenin+1+wicnt);
    int nownum = 0, nowcnt = 0;
    for(int i=1;i<=wicnt;i++){
        if(whenin[i] != nownum){
            ans += 1ll * nowcnt * b[nowcnt];
            nownum = whenin[i], nowcnt = 1;
        }else nowcnt ++;
    }
    ans += 1ll*nowcnt*b[nowcnt];
    return ans;
}


int main(){
    freopen("list.in", "r", stdin);
    freopen("list.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin>>n;
    int maxi = 0;
    for(int i=1;i<=n;i++){
        cin>>k[i];
        int tmp;
        for(int j=1;j<=k[i];j++){
            cin>>tmp;
            maxi = max(maxi, tmp);
            a[i].push_back(tmp);
        }
    }
    cin>>c; 
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    ll mini = 0x3f3f3f3f3f3f3f3f;
    int minpos = 1;
    for(int i=1;i<=maxi;i++){
        ll res = calc(i);
        if(res < mini){
            mini = res;
            minpos = i;
        }
    }
    int l = minpos;
    while(calc(minpos+1) == mini) minpos ++;
    cout<<mini<<' '<<minpos-l+1<<'\n';
    for(int i=l;i<=minpos;i++) cout<<i<<' ';
    return 0;
}